﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using td.Core;
using td.Core.DiscoverAddins;
using System.Threading;
using CG.Security.Principal;

namespace td.Core
{
    public class SecurityRoleManagerView : td.Core.AbstractViewContent
    {
        td.Core.Security.RoleManagerForm view = new Security.RoleManagerForm();
        public override DevExpress.XtraEditors.XtraUserControl ViewContentControl
        {
            get { return this.view; }
        }
        public override string Title
        {
            get
            {
                return "角色管理";
            }
            set
            {
                base.Title = value;
            }
        }
    }
    public class SecurityRoleManagerCommand:td.Core.AbstractToolButtonCommand
    {
        public override void Run()
        {
            var p = WorkBenchSingleTon.WorkBench.GetTabPage("角色管理");
            if (p == null)
            {
                WorkBenchSingleTon.WorkBench.AddView(new SecurityRoleManagerView());
            }
        }
        public override bool IsEnabled
        {
            get
            {
                var p = WorkBenchSingleTon.WorkBench.GetTabPage("角色管理");
                CustomPrincipal cp = (CustomPrincipal)Thread.CurrentPrincipal; ;
                CustomIdentity ci = (CustomIdentity)cp.Identity;

                return p == null && cp.IsInRole("Admin");
                
                
            }
            set
            {
                base.IsEnabled = value;
            }
        }
    }
}
